package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/8 20:35
 * https://leetcode.cn/problems/number-of-provinces/
 */
public class Title543II {

    int n, m, count;

    public int findCircleNum(int[][] isConnected) {
        n = isConnected.length;
        m = isConnected[0].length;
        count = 0;
        for (int i = 0; i < n; i++) {
            if (isConnected[i][i] != 2) {
                dfs(isConnected, i);
                count++;
            }
        }
        return count;
    }

    private void dfs(int[][] isConnected, int i) {
        //访问过
        if (isConnected[i][i] == 2) {
            return;
        }
        isConnected[i][i] = 2;
        int[] ints = isConnected[i];
        for (int k = 0; k < ints.length; k++) {
            if (isConnected[i][k] == 1) {
                dfs(isConnected, k);
            }
        }
    }

    public static void main(String[] args) {

    }
}
